import { load, loadDict, extract, cut } from "@node-rs/jieba";
import { readFileSync } from "fs";
import { fileURLToPath } from "node:url";
import { dirname } from "node:path";
console.log(fileURLToPath(import.meta.url));

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

console.log("__dirname", __dirname);
console.log("__filename", __filename);

// load();

/*
加载自定义词典：https://github.hscsec.cn/napi-rs/node-rs/issues/55

https://github.com/luckykaiyi/nodejieba

https://zhuanlan.zhihu.com/p/46922291

https://hanlp.hankcs.com/demos/pos.html#%E8%B0%83%E7%94%A8%E6%96%B9%E6%B3%95

https://blog.csdn.net/weixin_44826203/article/details/107484634

https://github.com/baidu/lac

https://zhuanlan.zhihu.com/p/180098564

https://cloud.tencent.com/developer/article/2192788

https://zhuanlan.zhihu.com/p/349117058

https://github.com/NLPchina/ansj_seg/wiki/%E6%96%B0%E8%AF%8D%E5%8F%91%E7%8E%B0%E5%B0%8F%E5%B7%A5%E5%85%B7

https://npmmirror.com/package/nodejieba
*/
const buffer = readFileSync(`${__dirname}/userdict.utf8`);
loadDict(buffer);

const text = "我们中出了一个叛徒";
// 精确模式
console.log(cut(text, false));
// 全模式
console.log(cut(text, true));
console.log(cut("中南林业科技大学是个不错的学校"));
console.log(cut("this is best tester, jack"));

const topN = 4;

console.log(extract("升职加薪，当上CEO，走上人生巅峰。", topN));
